improve error message when SETCREDS overwrites git-annex config
authorJoey Hess <joeyh@joeyh.name>
Tue, 16 Sep 2025 17:22:14 +0000 (13:22 -0400)
committerJoey Hess <joeyh@joeyh.name>
Tue, 16 Sep 2025 17:22:14 +0000 (13:22 -0400)
That is not allowed, so it's not a bug in git-annex when it happens and
instead tell the special remote developer how it's messed up.

Note that currently only Remote.External can overwrite the parsed remote
config with a PassedThrough value. PassedThrough values are otherwise
only generated for configs that are not parsed by the remote config
parser.

Sponsored-by: Joshua Antonishen
Annex/SpecialRemote/Config.hs
doc/todo/encrypt_only_the_credentials/comment_8_7ec2d0de7c0b90f05475b86148982197._comment [new file with mode: 0644]

index 5f9d6db8312f08692b2bac2e09de835f2be443a9..925b7e837c3d16787eaa35570d490b3ba508c4ee 100644 (file)
@@ -206,13 +206,23 @@ getRemoteConfigValue :: HasCallStack => Typeable v => RemoteConfigField -> Parse
 getRemoteConfigValue f (ParsedRemoteConfig m _) = case M.lookup f m of
        Just (RemoteConfigValue v) -> case cast v of
                Just v' -> Just v'
-               Nothing -> error $ unwords
-                       [ "getRemoteConfigValue"
-                       , fromProposedAccepted f
-                       , "found value of unexpected type"
-                       , show (typeOf v) ++ "."
-                       , "This is a bug in git-annex!"
-                       ]
+               Nothing -> case cast v :: Maybe PassedThrough of
+                       -- Handle the case where an external special remote
+                       -- tries to SETCONFIG a value belonging to git-annex,
+                       -- resulting in a PassedThrough type being stored.
+                       Just _ -> error $ unwords
+                               [ "Special remote config "
+                               , fromProposedAccepted f
+                               , "has been overwritten by SETCONFIG."
+                               , "This is not supported."
+                               ]
+                       Nothing -> error $ unwords
+                               [ "getRemoteConfigValue"
+                               , fromProposedAccepted f
+                               , "found value of unexpected type"
+                               , show (typeOf v) ++ "."
+                               , "This is a bug in git-annex!"
+                               ]
        Nothing -> Nothing
 
 {- Gets all fields that remoteConfigRestPassthrough matched. -}
diff --git a/doc/todo/encrypt_only_the_credentials/comment_8_7ec2d0de7c0b90f05475b86148982197._comment b/doc/todo/encrypt_only_the_credentials/comment_8_7ec2d0de7c0b90f05475b86148982197._comment
new file mode 100644 (file)
index 0000000..65c6774
--- /dev/null
@@ -0,0 +1,24 @@
+[[!comment format=mdwn
+ username="joey"
+ subject="""comment 8"""
+ date="2025-09-16T16:57:11Z"
+ content="""
+SETCONFIG is limited to setting the external program's configuration,
+not to reaching inside git-annex and setting its own configuration.
+The docs say that, but could perhaps be more clear.
+
+I have improved the error message.
+
+git-annex sets up encryption for the remote based on the encryption= and
+encryptonlycreds= settings before it ever starts up the external program.
+That would need to change in order to support this.
+
+But I'm also doubtful it would be a good idea to support SETCONFIG
+of any of the things git-annex uses for encryption, chunking, etc.
+It's essentially monkey-patching git-annex from the external program.
+Some changes to git-annex's configs could lead to very unexpected behavior.
+
+If you really need the ability to turn on onlyencryptcreds by default
+with your special remote, there will need to be some other way implemented
+to do it. Please open a new todo about that.
+"""]]